package com.ycsyxt.guide;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Lists;

/**
 * 组合：从n个不同元素中取出m个不同的元素。
 * 可能数量=n!/(m! * (n-m)!)
 * @author ycs(15241496739 @ 163.com)
 * @date 2022/6/12
 **/
public class Class8 {
    public static List<List<Integer>> result = new ArrayList<>();
    public static List<Integer> path = new ArrayList<>();

    public static void main(String[] args) {
        // 从10人中，抽取3等奖3名，2等奖2名，1等奖1名
        List<Integer> total = Lists.newArrayList(0,1,2,3,4,5,6,7,8,9);

        int sum = 1;
        backTracking(total, 0, 1);
        sum = sum * (result.size());
        result.clear();
        total.remove(0);
        backTracking(total, 0, 2);
        sum = sum * (result.size());
        result.clear();
        total.remove(0);
        total.remove(0);
        backTracking(total, 0, 3);
        sum = sum * (result.size());
        result.clear();

        System.out.println(sum);
    }

    private static void backTracking(List<Integer> total, int start, int level) {
        if (path.size() == level) {
            result.add(new ArrayList<>(path));
            return;
        }

        for (int i = start; i < total.size(); i++) {
            path.add(total.get(i));
            backTracking(total, i + 1, level);
            path.remove(path.size() - 1);
        }
    }
}
